package com.tanhua.server.controller;


import com.tanhua.model.vo.PageResult;
import com.tanhua.server.server.CommentsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping("/comments")
@RestController
@Slf4j
public class CommentsController {

    @Autowired
    private CommentsService commentsService;


    /**
     * 查询评论
     * @return
     */
    @GetMapping
    public ResponseEntity comments(String movementId,
                                   @RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult resultList = commentsService.findComments(movementId,page,pagesize);
        return ResponseEntity.ok(resultList);
    }


    @PostMapping
    public ResponseEntity submitComments(@RequestBody Map map){
        String movementId = (String) map.get("movementId");
        String comment = (String) map.get("comment");
        commentsService.saveComments(movementId, comment);
        return ResponseEntity.ok(null);
    }


/*    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String movementId) {
        Integer likeCount = commentsService.list(movementId);
        return ResponseEntity.ok(likeCount);
    }
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable("id") String movementId){
        Integer all = commentsService.dislike(movementId);
        return ResponseEntity.ok(all);
    }*/

    /**
     * 评论点赞
     */
    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String id){
        log.info("id={}",id);
        Integer all = commentsService.commentslike(id);
        return ResponseEntity.ok(all);
    }

    /**
     * 取消点赞
     * @param id
     * @return
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable("id") String id){
        log.info("id={}",id);
        Integer all = commentsService.commentsdislike(id);
        return ResponseEntity.ok(all);
    }

}


